
#ifndef __COMPILER_QUAD_HPP__
#define __COMPILER_QUAD_HPP__

#include <iostream>
#include <string>
#include <vector>

class Quad
{
public:
  Quad( const std::string& operation,
        const std::string& dst,
        const std::string& opA,
        const std::string& opB )
  : _operation( operation ),
    _dst( dst ),
    _opA( opA ),
    _opB( opB )
  {}

  void Emit( std::ostream& out )
  {
    EmitQuad( out, _operation, _dst, _opA, _opB );
  }

  static void EmitQuad( std::ostream& out,
                        const std::string& operation,
                        const std::string& dst,
                        const std::string& opA,
                        const std::string& opB )
  {
    out << operation << " " << dst << " " << opA << " " << opB << std::endl;
  }

  void Patch( const std::string& label )
  {
    if( _operation == "__patchable" ) _operation = label;
    if( _dst == "__patchable" ) _dst = label;
    if( _opA == "__patchable" ) _opA = label;
    if( _opB == "__patchable" ) _opB = label;

    std::clog << "Patching: " << _operation << " " << _dst << " " << _opA << " " << _opB << std::endl;
  }

  std::string _operation;
  std::string _dst;
  std::string _opA;
  std::string _opB;
};

typedef std::vector< Quad > QuadArray;

#endif // __COMPILER_QUAD_HPP__
